package com.wang.rabbitmqstudy.web;

import com.wang.rabbitmqstudy.config.PropertiesConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "异常示例")
@RestController
@RequestMapping("/error")
public class ErrorController {
    @Autowired
    private RabbitMessagingTemplate rabbitMessagingTemplate;
    @Autowired
    private PropertiesConfig propertiesConfig;

    /**
     * 路由键匹配失败，相当于发到交换机之后，找不到数据
     */
    @ApiOperation(value = "路由键匹配失败")
    @GetMapping("/directWithNoRoutingKey")
    public String directWithNoRoutingKey() {
        String payload = "directWithNoRoutingKey";
        String routingKey = "hello";
        rabbitMessagingTemplate.convertAndSend(propertiesConfig.getDirectExchange(), routingKey, payload);
        return "directWithNoRoutingKey done";
    }
}
